package com.ouc.yyi.test03;

import java.util.Scanner;

public class Test {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        Goods g = new Goods();
        System.out.print("请输入用户名：");
        String userName = input.next();
        System.out.print("请输入密码：");
        String password = input.next();
        if(g.login(userName,password)){
            g.showGoods();
            System.out.print("请输入您要批发的商品编号：");
            int no= input.nextInt();
            System.out.print("请输入商品的批发数量：");
            int num = input.nextInt();
            double total = g.buy(no, num);
            StringBuffer str = g.change(total);
            System.out.println("你需要付款："+str);
        }else{
            System.out.println("用户名或密码不正确，请重新输入！");
        }
    }
    //用户登录
    public boolean login(String name,String password){
        boolean isRegister = false;
        if(name.equals("Tom")&&password.equals("123456")){
            isRegister = true;
            System.out.println("登陆成功！");
        }
        return isRegister;
    }

    //总金额输出处理
    public StringBuffer change(double total){
        StringBuffer sb = new StringBuffer(String.valueOf(total));
        for(int i=sb.indexOf(".")-3;i>0;i=i-3){
            sb.insert(i,",");
        }
        return sb;
    }
    //每个三个数字插入","
    class StringBufferDemo{
        public StringBuffer display(String s){
            StringBuffer sb = new StringBuffer(s);
            for(int i=sb.length()-3;i>0;i=i-3){
                sb.insert(i,",");
            }
            return sb;
        }
}
}
